var mysql = require('mysql');
var express = require('express');
var app = express();
var connection = mysql.createConnection({
  host: '127.0.0.1',
  port: '3306',
  user: 'root',
  password: 'admin',
  database: 'db_message'
})
// SELECT english 
// FROM `cet`
// WHERE english IN (SELECT english FROM tb_t)
connection.connect();
var getSql = 'SELECT * FROM tb_message';
var insertSql = ''
var str = '';
var str1 = '';
var str11 = '';
var str22 = '';
var impo = [];
connection.query(getSql, function(err, result){
  if(err)
    console.log('SELECT ERROR:' + err);
  // console.log(result);
  str = JSON.stringify(result);
  str2 = str.replace(/\\n/g,'');
  str2 = str2.replace(/\\r/g,'');
  str2 = str2.replace(/\\t/g,'');

  str1 = JSON.parse(str2);
  impo = str1[0].content.split(" ");
  // console.log(impo);
  // impo.forEach(function(word){
  //   console.log(word);
  // })
  console.log(str);
});
app.get('/', function(req, res) {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.send(str);
});

app.listen(4000, function(){
  console.log("Server running at 4000 port");
})